From 5376f076cd41eefd4623a1a0d7cb53ac8211dba5 Mon Sep 17 00:00:00 2001 From: "kfraser@localhost.localdomain" Date: Mon, 10 Jul 2006 17:05:44 +0100 Subject: [PATCH] [XENTRACE] Remember number of lost trace records when trace buffer is full and write a 'number of lost records' entry when space becomes available. From: Rob Gardner Signed-off-by: Keir Fraser --- xen/common/trace.c | 21 +++++++++++++++++++-- xen/include/public/trace.h | 1 + 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/xen/common/trace.c b/xen/common/trace.c index 7e480d0bb4..d3d570e70d 100644 --- a/xen/common/trace.c +++ b/xen/common/trace.c @@ -46,6 +46,8 @@ static int nr_recs; /* Send virtual interrupt when buffer level reaches this point */ static int t_buf_highwater; +/* Number of records lost due to per-CPU trace buffer being full. */ +static DEFINE_PER_CPU(unsigned long, lost_records); /* a flag recording whether initialization has been done */ /* or more properly, if the tbuf subsystem is enabled right now */ @@ -234,7 +236,7 @@ void trace(u32 event, unsigned long d1, unsigned long d2, struct t_buf *buf; struct t_rec *rec; unsigned long flags; - + BUG_ON(!tb_init_done); if ( (tb_event_mask & event) == 0 ) @@ -259,12 +261,27 @@ void trace(u32 event, unsigned long d1, unsigned long d2, local_irq_save(flags); - if ( (buf->prod - buf->cons) >= nr_recs ) + /* Check if space for two records (we write two if there are lost recs). */ + if ( (buf->prod - buf->cons) >= (nr_recs - 1) ) { + this_cpu(lost_records)++; local_irq_restore(flags); return; } + if ( unlikely(this_cpu(lost_records) != 0) ) + { + rec = &t_recs[smp_processor_id()][buf->prod % nr_recs]; + memset(rec, 0, sizeof(*rec)); + rec->cycles = (u64)get_cycles(); + rec->event = TRC_LOST_RECORDS; + rec->data[0] = this_cpu(lost_records); + this_cpu(lost_records) = 0; + + wmb(); + buf->prod++; + } + rec = &t_recs[smp_processor_id()][buf->prod % nr_recs]; rec->cycles = (u64)get_cycles(); rec->event = event; diff --git a/xen/include/public/trace.h b/xen/include/public/trace.h index 8fc009dfeb..4cb73386c3 100644 --- a/xen/include/public/trace.h +++ b/xen/include/public/trace.h @@ -26,6 +26,7 @@ #define TRC_VMXIO 0x00088000 /* VMX io emulation trace */ /* Trace events per class */ +#define TRC_LOST_RECORDS (TRC_GEN + 1) #define TRC_SCHED_DOM_ADD (TRC_SCHED + 1) #define TRC_SCHED_DOM_REM (TRC_SCHED + 2) -- 2.30.2